

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Moe Wang">
  <meta name="keywords" content="">
  
    <meta name="description" content="DOM DOM 什么是DOM window对象和document对象 获取HTML元素 1. getElementById() 2. getElementsByTagName() 3. getElementsByClassName() 4. querySelector() 5. querySelectorAll()   操作HTML元素的属性 操作HTML元素的style 修改DOM中的内容 in">
<meta property="og:type" content="article">
<meta property="og:title" content="DOM">
<meta property="og:url" content="https://moewang0321.github.io/2019/08/06/2019-08-06-DOM/index.html">
<meta property="og:site_name" content="moe_大杂烩">
<meta property="og:description" content="DOM DOM 什么是DOM window对象和document对象 获取HTML元素 1. getElementById() 2. getElementsByTagName() 3. getElementsByClassName() 4. querySelector() 5. querySelectorAll()   操作HTML元素的属性 操作HTML元素的style 修改DOM中的内容 in">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://moewang0321.github.io/images/inner%E6%8E%A7%E5%88%B6%E5%8F%B0_1.png">
<meta property="og:image" content="d:/GitHub/moewang0321.github.io/images/inner页面变化.png">
<meta property="article:published_time" content="2019-08-06T06:46:25.000Z">
<meta property="article:modified_time" content="2023-02-14T07:48:54.733Z">
<meta property="article:author" content="Moe Wang">
<meta property="article:tag" content="JavaScript">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://moewang0321.github.io/images/inner%E6%8E%A7%E5%88%B6%E5%8F%B0_1.png">
  
  
  
  <title>DOM - moe_大杂烩</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"moewang0321.github.io","root":"/","version":"1.9.4","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 5.4.2"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>moe_大杂烩</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="DOM"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2019-08-06 14:46" pubdate>
          2019年8月6日 下午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          2.8k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          24 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">DOM</h1>
            
            
              <div class="markdown-body">
                
                <h1 id="DOM"><a href="#DOM" class="headerlink" title="DOM"></a>DOM</h1><ul>
<li><a href="#dom">DOM</a><ul>
<li><a href="#%E4%BB%80%E4%B9%88%E6%98%AFdom">什么是DOM</a></li>
<li><a href="#window%E5%AF%B9%E8%B1%A1%E5%92%8Cdocument%E5%AF%B9%E8%B1%A1">window对象和document对象</a></li>
<li><a href="#%E8%8E%B7%E5%8F%96html%E5%85%83%E7%B4%A0">获取HTML元素</a><ul>
<li><a href="#1-getelementbyid">1. getElementById()</a></li>
<li><a href="#2-getelementsbytagname">2. getElementsByTagName()</a></li>
<li><a href="#3-getelementsbyclassname">3. getElementsByClassName()</a></li>
<li><a href="#4-queryselector">4. querySelector()</a></li>
<li><a href="#5-queryselectorall">5. querySelectorAll()</a></li>
</ul>
</li>
<li><a href="#%E6%93%8D%E4%BD%9Chtml%E5%85%83%E7%B4%A0%E7%9A%84%E5%B1%9E%E6%80%A7">操作HTML元素的属性</a></li>
<li><a href="#%E6%93%8D%E4%BD%9Chtml%E5%85%83%E7%B4%A0%E7%9A%84style">操作HTML元素的style</a></li>
<li><a href="#%E4%BF%AE%E6%94%B9dom%E4%B8%AD%E7%9A%84%E5%86%85%E5%AE%B9">修改DOM中的内容</a><ul>
<li><a href="#innerhtml%E8%8E%B7%E5%8F%96%E5%85%83%E7%B4%A0%E9%87%8C%E7%9A%84%E5%86%85%E5%AE%B9">innerHTML：获取元素里的内容</a></li>
<li><a href="#innertext">innerText</a></li>
<li><a href="#documentwrite">document.write</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="什么是DOM"><a href="#什么是DOM" class="headerlink" title="什么是DOM"></a>什么是DOM</h2><p>JavaScript分为三个部分，分别为ECMAScript、DOM、BOM。<br>其中    DOM 是 文档对象模型（Document Object Model，简称DOM），是W3C组织推荐的处理可扩展标志语言的标准编程接口。在网页上，组织页面（或文档）的对象被组织在一个树形结构中，用来表示文档中对象的标准模型。</p>
<h2 id="window对象和document对象"><a href="#window对象和document对象" class="headerlink" title="window对象和document对象"></a>window对象和document对象</h2><p>window对象是包含document对象的。window对象是JS的最外层对象而document对象是DOM的最外层对象。</p>
<h2 id="获取HTML元素"><a href="#获取HTML元素" class="headerlink" title="获取HTML元素"></a>获取HTML元素</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>( <span class="hljs-variable language_">document</span>.<span class="hljs-property">doctype</span> );   <span class="hljs-comment">//    &lt;!DOCTYPE html&gt;</span><br>   <br><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>( <span class="hljs-variable language_">document</span>.<span class="hljs-property">documentElement</span> );    <span class="hljs-comment">//  &lt;html&gt;</span><br><br><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>( <span class="hljs-variable language_">document</span>.<span class="hljs-property">head</span> );     <span class="hljs-comment">// &lt;head&gt;</span><br><br><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>( <span class="hljs-variable language_">document</span>.<span class="hljs-property">body</span> );     <span class="hljs-comment">// &lt;body&gt;</span><br><br><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>( <span class="hljs-variable language_">document</span>.<span class="hljs-property">title</span> );     <span class="hljs-comment">// &lt;title&gt;中的内容 -&gt; Document</span><br><br><span class="hljs-variable language_">document</span>.<span class="hljs-property">title</span> = <span class="hljs-string">&#x27;nihao&#x27;</span>;     <span class="hljs-comment">// 还可以设置</span><br><br> <span class="hljs-comment">//注：.的含义，就是谁谁谁下的，下一级的意思。</span><br><br></code></pre></td></tr></table></figure>

<p><strong>注意：document.title获取到的不是title标签而是标签中的内容！</strong>  </p>
<p><strong>获取HTML元素通常有以下几种方法</strong></p>
<p><strong>获取元素操作的时候，尽量放在下边，让HTML元素加载完，要不然会获取不到</strong></p>
<h3 id="1-getElementById"><a href="#1-getElementById" class="headerlink" title="1. getElementById()"></a>1. getElementById()</h3><p>通过id获取元素</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs dart"><span class="hljs-keyword">var</span> elem = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">&#x27;elem&#x27;</span>); <br></code></pre></td></tr></table></figure>

<h3 id="2-getElementsByTagName"><a href="#2-getElementsByTagName" class="headerlink" title="2. getElementsByTagName()"></a>2. getElementsByTagName()</h3><p><strong>注意Elements有s！且获取到的为一个集合</strong></p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs dart"><span class="hljs-keyword">var</span> lis = <span class="hljs-built_in">document</span>.getElementsByTagName(<span class="hljs-string">&#x27;li&#x27;</span>);<br></code></pre></td></tr></table></figure>

<h3 id="3-getElementsByClassName"><a href="#3-getElementsByClassName" class="headerlink" title="3. getElementsByClassName()"></a>3. getElementsByClassName()</h3><p><strong>注意Elements有s！且获取到的为一个集合</strong></p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs dart"><span class="hljs-keyword">var</span> boxs = <span class="hljs-built_in">document</span>.getElementsByClassName(<span class="hljs-string">&#x27;box&#x27;</span>);  <br></code></pre></td></tr></table></figure>

<p><strong>getElementById的前边只可以是document，而getElementsByTagName和getElementsByClassName不一定</strong></p>
<h3 id="4-querySelector"><a href="#4-querySelector" class="headerlink" title="4. querySelector()"></a>4. querySelector()</h3><p>仿照CSS选择器而诞生的，写法和CSS选择器类似</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs dart"><span class="hljs-keyword">var</span> elem = <span class="hljs-built_in">document</span>.<span class="hljs-built_in">querySelector</span>(<span class="hljs-string">&#x27;#elem&#x27;</span>)<br></code></pre></td></tr></table></figure>

<h3 id="5-querySelectorAll"><a href="#5-querySelectorAll" class="headerlink" title="5. querySelectorAll()"></a>5. querySelectorAll()</h3><p>仿照CSS选择器而诞生的，写法和CSS选择器类似，返回的是一个集合。</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs dart"><span class="hljs-keyword">var</span> boxs = <span class="hljs-built_in">document</span>.<span class="hljs-built_in">querySelectorAll</span>(<span class="hljs-string">&#x27;.box&#x27;</span>); <br><span class="hljs-keyword">var</span> lis = <span class="hljs-built_in">document</span>.<span class="hljs-built_in">querySelectorAll</span>(<span class="hljs-string">&#x27;ul li&#x27;</span>);  <br></code></pre></td></tr></table></figure>

<h2 id="操作HTML元素的属性"><a href="#操作HTML元素的属性" class="headerlink" title="操作HTML元素的属性"></a>操作HTML元素的属性</h2><p><strong>注：class关键字被JS中的面向对象中的类所占用了，用className来获取class样式属性，同样的，for被JS中的循环占用了，所以HTML中的for属性需要写成htmlFor</strong></p>
<figure class="highlight arcade"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs arcade"><span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( elem.id );<br><span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( elem.title );<br><span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( elem.zidingyi );   <span class="hljs-comment">// .的方式获取不到自定义属性</span><br><span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( elem.className ); <br><span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( lab.htmlFor );<br></code></pre></td></tr></table></figure>

<h2 id="操作HTML元素的style"><a href="#操作HTML元素的style" class="headerlink" title="操作HTML元素的style"></a>操作HTML元素的style</h2><p>JS种不能出现短线- , 短线去掉转驼峰写法;</p>
<p>例如CSS中的<code>font-size:16px</code></p>
<p>在JS中就应该写成<code>fontSize:16px</code></p>
<figure class="highlight maxima"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs maxima"><span class="hljs-built_in">var</span> <span class="hljs-built_in">elem</span> = document.getElementById(&#x27;<span class="hljs-built_in">elem</span>&#x27;);     <br><span class="hljs-built_in">elem</span>.<span class="hljs-built_in">style</span>.<span class="hljs-built_in">background</span> = &#x27;red&#x27;;<br><span class="hljs-built_in">elem</span>.<span class="hljs-built_in">style</span>.<span class="hljs-built_in">color</span> = &#x27;white&#x27;;<br><span class="hljs-built_in">elem</span>.<span class="hljs-built_in">style</span>.<span class="hljs-built_in">width</span> = &#x27;100px&#x27;; <br>//cssText可以简化样式的设置操作 , 注意会把<span class="hljs-built_in">style</span>样式进行整体覆盖掉<br><span class="hljs-built_in">elem</span>.<span class="hljs-built_in">style</span>.cssText = &#x27;<span class="hljs-built_in">width</span>:100px;<span class="hljs-built_in">background</span>:red;<span class="hljs-built_in">color</span>:white&#x27;;<br></code></pre></td></tr></table></figure>
<p>这种方法只能改变元素的内联样式，如果写的内部样式或者外部样式，应该怎么办呢？<br>这里提供一种方法<code>getComputedStyle()</code>  它获取的是元素的最终样式，即不管你是哪里的CSS，我只抓住最后呈现在页面上的样式！（挺霸道的……我感觉）</p>
<figure class="highlight maxima"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs maxima"><span class="hljs-built_in">var</span> <span class="hljs-built_in">elem</span> = document.getElementById(&#x27;<span class="hljs-built_in">elem</span>&#x27;);<br>console.<span class="hljs-built_in">log</span>( getComputedStyle(<span class="hljs-built_in">elem</span>).<span class="hljs-built_in">color</span> );<br>console.<span class="hljs-built_in">log</span>( getComputedStyle(<span class="hljs-built_in">elem</span>).fontSize );<br></code></pre></td></tr></table></figure>

<p>在一些老浏览器里不支持这么霸道的它，那怎么兼容啊</p>
<figure class="highlight maxima"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs maxima"><span class="hljs-built_in">var</span> <span class="hljs-built_in">elem</span> = document.getElementById(&#x27;<span class="hljs-built_in">elem</span>&#x27;);<br>console.<span class="hljs-built_in">log</span>( <span class="hljs-built_in">elem</span>.currentStyle.fontSize );<br></code></pre></td></tr></table></figure>

<p>这个方法老版本适用新版本不适用……挺气人的</p>
<h2 id="修改DOM中的内容"><a href="#修改DOM中的内容" class="headerlink" title="修改DOM中的内容"></a>修改DOM中的内容</h2><h3 id="innerHTML：获取元素里的内容"><a href="#innerHTML：获取元素里的内容" class="headerlink" title="innerHTML：获取元素里的内容"></a>innerHTML：获取元素里的内容</h3><figure class="highlight arcade"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs arcade"><span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( elem.innerHTML );   <span class="hljs-comment">// &#x27;&lt;h2&gt;hello&lt;/h2&gt;&#x27;</span><br>elem.innerHTML = <span class="hljs-string">&#x27;&lt;p&gt;这是一个段落&lt;/p&gt;&#x27;</span>; <br></code></pre></td></tr></table></figure>

<p><img src="/images/inner%E6%8E%A7%E5%88%B6%E5%8F%B0_1.png" srcset="/img/loading.gif" lazyload alt="enter description here"><br><strong>输出了id为elem的div里全部内容</strong><br><img src="D:\GitHub\moewang0321.github.io\images\inner页面变化.png" srcset="/img/loading.gif" lazyload><br><strong>innerHTML识别标签，自动将字符串转化为p标签</strong></p>
<h3 id="innerText"><a href="#innerText" class="headerlink" title="innerText"></a>innerText</h3><p>跟innerHTML用法相似但是不会获取标签，只会获取文本内容<br>上部代码如果将<code>innerHTML</code>变成 <code>innerText</code> 那页面上输出的将会是<code>&lt;p&gt;这是一个段落&lt;/p&gt;</code></p>
<h3 id="document-write"><a href="#document-write" class="headerlink" title="document.write"></a>document.write</h3><p>不常用，直接将文本内容输出到页面body中，了解即可</p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/study/" class="category-chain-item">study</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/JavaScript/">#JavaScript</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>DOM</div>
      <div>https://moewang0321.github.io/2019/08/06/2019-08-06-DOM/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Moe Wang</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2019年8月6日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2019/08/06/2019-08-06-%E5%88%9D%E5%85%A5js%EF%BC%88%E4%B8%89%EF%BC%89/" title="初入JS（三）">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">初入JS（三）</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2019/08/05/2019-08-06-%E5%88%9D%E5%85%A5JS%EF%BC%88%E4%BA%8C%EF%BC%89/" title="初入JS（二）">
                        <span class="hidden-mobile">初入JS（二）</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
    <div id="giscus" class="giscus"></div>
    <script type="text/javascript">
      Fluid.utils.loadComments('#giscus', function() {
        var options = {"repo":"moewang0321/moewang0321.github.io","repo-id":"MDEwOlJlcG9zaXRvcnkyMDEyNDI0NTY=","category":"Show and tell","category-id":"DIC_kwDOC_63WM4CUMsH","theme-light":"light_protanopia","theme-dark":"dark_dimmed","mapping":"pathname","reactions-enabled":1,"emit-metadata":1,"input-position":"top","loading":"lazy","lang":"zh-CN"};
        var attributes = {};
        for (let option in options) {
          if (!option.startsWith('theme-')) {
            var key = option.startsWith('data-') ? option : 'data-' + option;
            attributes[key] = options[option];
          }
        }
        var light = 'light_protanopia';
        var dark = 'dark_dimmed';
        window.GiscusThemeLight = light;
        window.GiscusThemeDark = dark;
        attributes['data-theme'] = document.documentElement.getAttribute('data-user-color-scheme') === 'dark' ? dark : light;
        for (let attribute in attributes) {
          var value = attributes[attribute];
          if (value === undefined || value === null || value === '') {
            delete attributes[attribute];
          }
        }
        var s = document.createElement('script');
        s.setAttribute('src', 'https://giscus.app/client.js');
        s.setAttribute('crossorigin', 'anonymous');
        for (let attribute in attributes) {
          s.setAttribute(attribute, attributes[attribute]);
        }
        var ss = document.getElementsByTagName('script');
        var e = ss.length > 0 ? ss[ss.length - 1] : document.head || document.documentElement;
        e.parentNode.insertBefore(s, e.nextSibling);
      });
    </script>
    <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
